<template>
  <div>
  <van-nav-bar
  title="登录"
    left-text="返回"
  right-text="注册"
  @click-left="$router.go(-1)"
  @click-right="onClickRight"
/>
<van-circle
  v-model="currentRate"
  rate="100"
  :color="gradientColor"
>
<div class="touxiang1">
<img src="@/assets/img/touxiang2.gif" alt="">
</div>
</van-circle>
<van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="userName"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="passWord"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">登录</van-button>
  </div>
</van-form>
  </div>
</template>

<script>
import Cookies from 'js-cookie'
import { login } from '@api'
export default {
  data () {
    return {
      username: '',
      password: '',
      currentRate: 0,
      gradientColor: {
        '0%': '#3fecff',
        '100%': '#6149f6'
      }
    }
  },
  methods: {
    onSubmit (values) {
      console.log('submit', values)
      login({ ...values }).then(res => {
        console.log(res)
        Cookies.set('token', res.data.token)
        console.log(res.data.token)
        if (res.data.status === 200) {
          this.$router.push({
            path: '/user',
            query: {
              name: values.userName
            }
          })
        }
      })
    },
    onClickRight () {
      this.$router.push({
        path: '/regist'
      })
    }
  },
  components: {
  }
}

</script>

<style lang="scss" scoped>
 .van-circle{
  margin: 50px auto;
  height: 200px;
  width: 100%;

}
.touxiang1{
  width:200px;
  height: 200px;
  margin: auto;
 background-color: red;
 border-radius: 50%;
 overflow: hidden;
}
.van-circle img{
  width: 100%;
  height: 100%;

}
</style>
